﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
using Albon.Model;

namespace DAL
{
    public class ItemSizeDAL
    {
        /// <summary>
        /// 添加一条itemsize数据
        /// </summary>
        public bool addItemSize(ItemSize itemsize)
        {
            SqlParameter[] parameters = new SqlParameter[] { 
                new SqlParameter("@orderitemid",itemsize.orderItemID),
                new SqlParameter("@sizetempleteid",itemsize.sizeTempleteID),
                new SqlParameter("@bodysize",itemsize.bodySize),
                new SqlParameter("@finishedsize",itemsize.finishedSize)
            };
            int ret = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_itemsizeadd", parameters);
            return ret > 0;
        }

        /// <summary>
        /// 根据orderitemid获取尺寸信息
        /// </summary>
        public DataTable getItemSize(string limit)
        {
            string cmdstr = "select * from ItemSizeView where " + limit;
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).Tables[0];
        }
        /// <summary>
        /// 根据OrderID获取尺寸信息
        /// </summary>
        public DataTable getOrderItemSize(string orderid)
        {
            string cmdstr = "select * from ItemSizeView where orderID=" + orderid;
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).Tables[0];
        }

        public DataTable getMaxOverSize(string orderitemid, string styleid)
        {
            SqlParameter[] parameters = new SqlParameter[] { 
                new SqlParameter("@orderItemID",orderitemid),
                new SqlParameter("@styleID",styleid)
            };
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_getmaxsize", parameters).Tables[0];
        }
    }
}
